Fix how the dataset reader uses its device module - #26
Merged
Conversation
DatasetReader is now generic over its device module, so device_module returns the module passed to the constructor rather than the DeviceModuleLike contract, and create_dataset_reader declares DatasetReader[DeviceModule]. Reaching a register through the device module in the reader now resolves to the register class itself for a pre-generated package, and collectively for a module built by create_device_module.
A device module now declares DEVICE_NAME, the device name from the schema, matching what the generator emits for a static package, and DeviceModuleLike requires it in place of __name__. DatasetReader takes the file prefix from name when given, then from DEVICE_NAME, then from the folder when it holds a single device. A pre-generated package therefore reads correctly, where the module name used before is its dotted import path and matches no file.
The keyword controlling converter resolution is now require_converters on create_registers, create_device_module and create_dataset_reader. Behavior is unchanged. A custom interfaceType with no matching entry in converters still raises UnknownConverterError, and passing False still decodes it as its native element type. The error message now names the flag rather than explaining what strict meant.
DatasetReader compares the WHO_AM_I of its device module with the whoAmI declared by the device.yml in the folder, and raises when they disagree, so a module reused across sessions and reaching the wrong folder fails on construction rather than decoding the files against the wrong register map. The check is skipped when either side declares no identity, and when the schema does not describe a device pyharp can model. A schema that is not well-formed raises instead. validate=False turns off every check the reader performs.
DatasetReader no longer infers a device name from the file names in a folder. The prefix comes from name when given and otherwise from the DEVICE_NAME declared by the module, and construction fails when that is empty, as it is for a module built from a schema with no device header. DEVICE_NAME and WHO_AM_I are now read directly rather than through getattr, so a module that does not satisfy DeviceModuleLike raises AttributeError. The dataset fixtures take their prefix from DEVICE_NAME rather than from the module __name__, which were equal only by coincidence, and the chunk test now uses ISO 8601 UTC timestamps in basic format to illustrate lexicographic sorting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three defects in
DatasetReadersurfaced while reviewing documentation ahead of the release, two of which made the reader silently wrong. A fourth change renamesstricttorequire_converters, to make its meaning explicit and avoid clashing with the newvalidateflag.Preserve the device module type
DatasetReaderis now generic over its device module, mirroringDevice.device_modulereturns the module type passed to the constructor, so registers reached through the reader resolve exactly as they do on the module itself.Match files by the declared device name
A device module now declares the name used to prefix its recordings under
DEVICE_NAME, andDeviceModuleLikerequires it in place of__name__. The reader takes the file prefix fromnamewhen given, then fromDEVICE_NAME, then from the folder itself when it holds a single device, which covers a schema that declares no name at all.The prefix previously came from the module
__name__, which is the dotted import path for a pre-generated package, soDatasetReader(behavior, folder)matched no files and a whole session read as empty with no error.Validate device identity
The reader now compares the module
WHO_AM_Iagainst thewhoAmIin the folderdevice.yml, and refuses to construct when they disagree. A module reused across sessions and reaching the wrong folder therefore fails on construction rather than decoding the files against the wrong register map.validate=Falseturns off every check the reader performs, so a folder whosedevice.ymlis damaged can be read with a module obtained elsewhere.Rename strict to require_converters
strictis nowrequire_convertersoncreate_registers,create_device_moduleandcreate_dataset_reader. Behavior is unchanged. An unresolved custominterfaceTypestill raisesUnknownConverterError, and passingFalsestill decodes it as the native element type.The old name said nothing about converters, and read as the same kind of switch as the new
validatewhile sitting on the opposite side of the data boundary.validate=Falsechanges whether a check runs, whereasrequire_converters=Falsechanges the decoded values.